#!/bin/sh
#自动巡检
ding=https://oapi.dingtalk.com/robot/send?access_token=605b3322af99285c0fe8426f42172fc3155efbac6885b8578e3750cce63d8378
host=`cat /etc/hostname`
dir=`dirname $0`

diskinfo()
{
  disk=`df -h | grep ^/ | awk '{printf "##### %s   %s  \\\n  ",$NF,$(NF-1)}'`
  echo $disk
}
# awk $0代表整行 $1 第一列  $NF 倒数最后一列  $(NF-1) 倒数第二列
meminfo()
{
  mem=`free -h|grep -v ^- | grep -v Swap | awk '{printf "##### %s  \\\n  ",$0}'`
  echo $mem
}

cpuinfo()
{
  cpu=`uptime`
  echo "##### $cpu"
}

disk=`diskinfo`
mem=`meminfo`
cpu=`cpuinfo`


title="$host 巡检"
body="## $title \n "
body+="### CPU负载 \n $cpu \n ### 内存使用 \n $mem ### 磁盘使用 \n $disk \n "
echo $body
sh $dir/push_ding.sh "$ding" "$title" "$body"